package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.constant.CacheKeyConstants;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.system.domain.WdyProduct;
import com.ruoyi.system.service.IWdyProductService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 理财产品 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-12-15
 */
@Controller
@RequestMapping("/system/wdyProduct")
public class WdyProductController extends BaseController
{
    private String prefix = "system/wdyProduct";
	@Autowired
	protected RedisTemplate redisTemplate;
	@Autowired
	private IWdyProductService wdyProductService;
	
	@RequiresPermissions("system:wdyProduct:view")
	@GetMapping()
	public String wdyProduct()
	{
	    return prefix + "/wdyProduct";
	}
	
	/**
	 * 查询理财产品列表
	 */
	@RequiresPermissions("system:wdyProduct:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(WdyProduct wdyProduct)
	{
		startPage();
        List<WdyProduct> list = wdyProductService.selectWdyProductList(wdyProduct);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出理财产品列表
	 */
	@RequiresPermissions("system:wdyProduct:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WdyProduct wdyProduct)
    {
    	List<WdyProduct> list = wdyProductService.selectWdyProductList(wdyProduct);
        ExcelUtil<WdyProduct> util = new ExcelUtil<WdyProduct>(WdyProduct.class);
        return util.exportExcel(list, "wdyProduct");
    }
	
	/**
	 * 新增理财产品
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存理财产品
	 */
	@RequiresPermissions("system:wdyProduct:add")
	@Log(title = "理财产品", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(WdyProduct wdyProduct)
	{		
		return toAjax(wdyProductService.insertWdyProduct(wdyProduct));
	}

	/**
	 * 修改理财产品
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		WdyProduct wdyProduct = wdyProductService.selectWdyProductById(id);
		mmap.put("wdyProduct", wdyProduct);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存理财产品
	 */
	@RequiresPermissions("system:wdyProduct:edit")
	@Log(title = "理财产品", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(WdyProduct wdyProduct)
	{
		String cacheKey = CacheKeyConstants.getTempletString(CacheKeyConstants.PRODUCT, String.valueOf(wdyProduct.getId()));
		redisTemplate.delete(cacheKey);
		return toAjax(wdyProductService.updateWdyProduct(wdyProduct));
	}
	
	/**
	 * 删除理财产品
	 */
	@RequiresPermissions("system:wdyProduct:remove")
	@Log(title = "理财产品", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(wdyProductService.deleteWdyProductByIds(ids));
	}
	
}
